﻿using Payroll.Biz.Legacy.DAL;
using Payroll.Biz.Legacy.Models;
using Payroll.Biz.Legacy.ServiceParams;
using Payroll.Biz.Legacy.Utils;
using System;
using System.Linq;

namespace Payroll.Biz.Legacy.Services
{
    public class AddCommissionedEmployeeService : AbstractService, IService<AddCommissionedEmployeeServiceParams>
    {
        public AddCommissionedEmployeeService(IPayrollDatabase database) : base(database)
        {
        }

        public ServiceResult Execute(AddCommissionedEmployeeServiceParams serviceParams)
        {
            IPaymentClassification paymentClassification = new CommissionClassification(
                serviceParams.BaseRate,
                serviceParams.CommissionRate);

            Guid id = Guid.NewGuid();

            Employee employee = EmployeeFactory.Create(
                id,
                serviceParams.Name,
                serviceParams.Address,
                paymentClassification);
            employee.Schedule = new BiWeeklySchedule();
            employee.Method = new HoldMethod();

            Database.AddEmployee(employee);

            return ServiceResult.CreateSuccessResult(employee.Id);
        }
    }
}
